package io.kiki.sba.registry.util;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

public abstract class WakeUpLoopExecuteTask extends LoopExecuteTask {
    private final ArrayBlockingQueue<Object> queue = new ArrayBlockingQueue<>(1);

    @Override
    public void _wait_() {
        ConcurrentUtils.pollUninterruptibly(queue, getWaitingMillis(), TimeUnit.MILLISECONDS);
    }

    public abstract int getWaitingMillis();

    public void wakeup() {
        queue.offer(this);
    }
}
